<html>
	<head>

		<script type="text/javascript">

		function writeResult(text)
		{
				var output = document.getElementById('output');
				var p = document.createElement("p");
				var nodeText = document.createTextNode(text);
				p.appendChild(nodeText);
				output.appendChild(p);
		}

		function stringFormat(format)
		{
			var args = Array.prototype.slice.call(arguments);//Convert arguments to array
			for(var i = 1; i <= args.length-1;i++)
			{
				var placeHolder="{"+(i-1)+"}";
				var index = format.indexOf(placeHolder);
				while(index !== -1)
				{
					format = format.replace(placeHolder,args[i]);
					index = format.indexOf(placeHolder);
				}
			}
			return format;
		}

		function onClick()
		{
			writeResult(stringFormat("{0}, {1}, {0} text {2}", 1, "Pesho", "Gosho"));
			writeResult(stringFormat("{0}, {1}, {0} text {2} {3} {4}", 1, "Pesho", "Gosho","Niki","Moni"));    
		}
		</script>
		<title></title>
	</head>
	<body>	
		<pre>
			writeResult(stringFormat("{0}, {1}, {0} text {2}", 1, "Pesho", "Gosho"));
			writeResult(stringFormat("{0}, {1}, {0} text {2} {3} {4}", 1, "Pesho", "Gosho","Niki","Moni"));
		</pre>
		<button onclick="onClick()" id="buttonOne">Parse</button>
		<p>
			Output
		</p>
		<div id="output"></div>
	</body>
</html>